package com.itbour.web.action.material;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.itbour.com.page.Page;
import com.itbour.common.base.BaseAction;
import com.itbour.common.util.StringUtils;
import com.itbour.dto.com.ProdVerInfoDto;
import com.itbour.dto.com.UserInfoDto;
import com.itbour.service.material.ProdVerInfoService;
import com.opensymphony.xwork2.ActionContext;

/**
 * 版本管理 Action
 * @author LQ
 */
public class GetProdVerInfoWebAction extends BaseAction {
	
	private static final long serialVersionUID = 1L;
	private ProdVerInfoService prodVerInfoService;
	private ProdVerInfoDto prodVerInfoDto;
	private HashMap<String, Object> mapResult=new HashMap<String, Object>();
	private List<ProdVerInfoDto> listResult;
	private String findTypeL;//平台分类
	private String findTypeM;//版本分类
	private String findTypeS;//是否有效
	private String findDesc;//描述信息
	
	
	
	
	/**分页获取版本信息内容
	 * @return mapResult
	 */
	public String pageListProdVerInfo() {
		Map<String, Object> session = ActionContext.getContext().getSession();
		UserInfoDto user = (UserInfoDto) session.get("user");
		if (user != null && user.getUser_id() != null) {
			Map<String, Object> parm = new HashMap<String, Object>();
			HttpServletRequest request = ServletActionContext.getRequest();
			Integer pageNum = Integer.parseInt(request.getParameter("page"));
			Integer pageSize = Integer.parseInt(request.getParameter("rows"));
			if(StringUtils.isNotEmpty(findTypeL)){
				if(Integer.parseInt(findTypeL)>0){
					parm.put("device", findTypeL);
				}
			}
			if(StringUtils.isNotEmpty(findTypeM)){
				parm.put("release", findTypeM);
			}
			if(StringUtils.isNotEmpty(findTypeS)){
				if(Integer.parseInt(findTypeS)>=0){
					parm.put("valid", findTypeS);
				}
			}
			if(StringUtils.isNotEmpty(findDesc)){
				parm.put("desc", findDesc);
			}
			Page page=prodVerInfoService.pageProdVerInfo(pageNum, pageSize, parm);
			mapResult.put("total", page.getTotalCount());
			mapResult.put("rows", page.getResult());
		}
		return SUCCESS;
	}

	
	/** 添加版本信息
	 **/
	public void addProdVerInfo() throws Exception {
		if (prodVerInfoDto != null) {
			Map<String, Object> session = ActionContext.getContext().getSession();
			UserInfoDto user = (UserInfoDto) session.get("user");
			if (user != null && user.getUser_id() != null) {
				prodVerInfoDto.setUpdate_by(user.getUser_id().toString());
				if (prodVerInfoDto.getId()!=null) {
					this.updProdVerInfo();//修改信息
				} else {
					prodVerInfoService.addProdVerInfo(prodVerInfoDto);;
					this.writeJSON("ok");
				}
			}else{
				this.writeJSON("no");
			}
		} else {
			this.writeJSON("no");
		}
	}
	
	/**修改版本
	 */
	public void updProdVerInfo() throws Exception{
		if (prodVerInfoDto != null) {
			Map<String, Object> session = ActionContext.getContext().getSession();
			UserInfoDto user = (UserInfoDto) session.get("user");
			if (user != null && user.getUser_id() != null) {
				prodVerInfoDto.setUpdate_by(user.getUser_id().toString());
				prodVerInfoService.updProdVerInfo(prodVerInfoDto);
				this.writeJSON("ok");
			} else {
				this.writeJSON("no");
			}
		} else {
			this.writeJSON("no");
		}
	}
	
	/**获取单个信息
	 */
	public String getOneProdVerInfo(){
		HttpServletRequest request=ServletActionContext.getRequest();
		Integer id=Integer.parseInt(request.getParameter("id"));
		if(id!=null){
			Map<String, Object> parm=new HashMap<String, Object>();
			parm.put("id", id);
			listResult=prodVerInfoService.getOneProdVerInfo(parm);
		}
		return SUCCESS;
	}
	
	/**删除版本信息
	 */
	public void delProdVerInfo() throws Exception{
		HttpServletRequest request=ServletActionContext.getRequest();
		Map<String, Object> session=ActionContext.getContext().getSession();
		UserInfoDto user=(UserInfoDto)session.get("user");
		String ids=request.getParameter("ids");
		if(ids!=null&&user.getUser_id()!=null&&ids.length()>0){
			Map<String, Object> parm=new HashMap<String, Object>();
			parm.put("ids", ids);
			parm.put("update_by", user.getUser_id());
			prodVerInfoService.delProdVerInfo(parm);
			this.writeJSON("ok");
		}
	}

	public ProdVerInfoService getProdVerInfoService() {
		return prodVerInfoService;
	}
	public void setProdVerInfoService(ProdVerInfoService prodVerInfoService) {
		this.prodVerInfoService = prodVerInfoService;
	}
	public HashMap<String, Object> getMapResult() {
		return mapResult;
	}
	public void setMapResult(HashMap<String, Object> mapResult) {
		this.mapResult = mapResult;
	}
	public static long getSerialversionuid() {
		return serialVersionUID;
	}
	public ProdVerInfoDto getProdVerInfoDto() {
		return prodVerInfoDto;
	}
	public void setProdVerInfoDto(ProdVerInfoDto prodVerInfoDto) {
		this.prodVerInfoDto = prodVerInfoDto;
	}
	public List<ProdVerInfoDto> getListResult() {
		return listResult;
	}
	public void setListResult(List<ProdVerInfoDto> listResult) {
		this.listResult = listResult;
	}


	public String getFindTypeL() {
		return findTypeL;
	}
	public void setFindTypeL(String findTypeL) {
		this.findTypeL = findTypeL;
	}
	public String getFindTypeM() {
		return findTypeM;
	}
	public void setFindTypeM(String findTypeM) {
		this.findTypeM = findTypeM;
	}
	public String getFindTypeS() {
		return findTypeS;
	}
	public void setFindTypeS(String findTypeS) {
		this.findTypeS = findTypeS;
	}
	public String getFindDesc() {
		return findDesc;
	}
	public void setFindDesc(String findDesc) {
		this.findDesc = findDesc;
	}
	
}
